#ifndef _FV_TXT_UTLS_H_
#define _FV_TXT_UTLS_H_

#include "fv_config.h"
#include "fv_inc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

#ifdef _WIN32
extern PFNGLGENBUFFERSARBPROC            pglGenBuffersARB;             // VBO Name Generation Procedure
extern PFNGLBINDBUFFERARBPROC            pglBindBufferARB;             // VBO Bind Procedure
extern PFNGLBUFFERDATAARBPROC            pglBufferDataARB;             // VBO Data Loading Procedure
extern PFNGLBUFFERSUBDATAARBPROC         pglBufferSubDataARB;          // VBO Sub Data Loading Procedure
extern PFNGLDELETEBUFFERSARBPROC         pglDeleteBuffersARB;          // VBO Deletion Procedure
extern PFNGLGETBUFFERPARAMETERIVARBPROC  pglGetBufferParameterivARB;   // return various parameters of VBO
extern PFNGLMAPBUFFERARBPROC             pglMapBufferARB;              // map VBO procedure
extern PFNGLUNMAPBUFFERARBPROC           pglUnmapBufferARB;            // unmap VBO procedure
#endif

// struct variable to store OpenGL info
struct glInfo
{
    std::string vendor;
    std::string renderer;
    std::string version;
    std::string glslVersion;
    std::vector <std::string> extensions;
    int redBits;
    int greenBits;
    int blueBits;
    int alphaBits;
    int depthBits;
    int stencilBits;
    int maxTextureSize;
    int maxLights;
    int maxAttribStacks;
    int maxModelViewStacks;
    int maxProjectionStacks;
    int maxClipPlanes;
    int maxTextureStacks;

    // ctor, init all members
    glInfo() : redBits(0), greenBits(0), blueBits(0), alphaBits(0), depthBits(0),
               stencilBits(0), maxTextureSize(0), maxLights(0), maxAttribStacks(0),
               maxModelViewStacks(0), maxClipPlanes(0), maxTextureStacks(0) {}

    bool getInfo(unsigned int param=0);         // extract info
    void printSelf();                           // print itself
    bool isExtensionSupported(const std::string& ext); // check if a extension is supported
};

// Returns width of given text in current screen coordinates
float getTextWidthOnScreen(const std::string& text, void* pCurrentFont);
void  drawText(const std::string& pText,
              float pXMin, float pYMin, float pXMax, float pYMax,
              int pFontSize, void* pCurrentFont, bool pAutoLineBreak, bool pFlagCentered);

void drawText3D(const std::string& pText, float pX, float pY, float pZ, void* pCurrentFont);
void drawString(const char *str, int x, int y, float color[4], void *font);
inline bool
__CheckErrorGL(const char *file, const int line)
{
    bool ret_val = true;

    // check for error
    GLenum gl_error = glGetError();

    if (gl_error != GL_NO_ERROR)
    {
#ifdef _WIN32
        char tmpStr[512];
        // NOTE: "%s(%i) : " allows Visual Studio to directly jump to the file at the right line
        // when the user double clicks on the error line in the Output pane. Like any compile error.
        sprintf_s(tmpStr, 255, "\n%s(%i) : GL Error : %s\n\n", file, line, gluErrorString(gl_error));
        fprintf(stderr, "%s", tmpStr);
#endif
        fprintf(stderr, "GL Error in file '%s' in line %d :\n", file, line);
        fprintf(stderr, "%s\n", gluErrorString(gl_error));
        fflush(stderr);
        ret_val = false;
    }

    return ret_val;
}
#define FV_DEBUG_GL 1
#ifdef FV_DEBUG_GL
#define FV_CHECK_ERROR_GL()                                             \
    if( false == __CheckErrorGL( __FILE__, __LINE__)) {                 \
        exit(EXIT_FAILURE);												\
    }
//#ifdef FV_DEBUG_GL
//#define FV_CHECK_ERROR_GL()	\
//{ \
//	GLenum err;	\
//	if (err = glGetError()) \
//		printf("GL Error in file: %s line: %d: %s\n", __FILE__, __LINE__ ,gluErrorString(err)); \
//}
#else
#define FV_CHECK_ERROR_GL()
#endif



#endif /* _FV_TXT_UTLS_H_
		*/
